package jsyf.oa.web.report.reportDayTree;

import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import jsyf.com.util.BaseUtils;
import jsyf.com.util.JsonUtils;
import jsyf.com.util.ResponseUtils;
import jsyf.oa.facade.report.reportDayTree.ReportDayTreeFacade;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * Created by jjx on 2018/5/30.
 */
@Api(value = "今日数据组织结构", description = "今日数据组织结构")
@Controller
@RequestMapping("/reportDay")
public class ReportDayTreeController {

    @Resource
    private ReportDayTreeFacade reportDayTreeFacade;

    @ApiOperation(
            value = "获取公司-部门-人员树形结构",
            notes = "获取公司-部门-人员树形结构",
            httpMethod = "POST",
            response = ResponseUtils.class,
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "jsonData", value = "", dataType = "参数类型（string）", paramType = "参数类型（json）")
    })
    @ResponseBody
    @RequestMapping(value = "/getOrgTreeNodesByUserId.json", method = RequestMethod.POST)
    public void getOrgInbox(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        List<JSONObject> records = this.reportDayTreeFacade.reportDayTree(jsonData);
        if (records != null) {
            ResponseUtils.putJsonResponse(response, BaseUtils.succsessArrRespond(records));
        } else {
            ResponseUtils.putJsonResponse(response, BaseUtils.errorrRespond("未找到数据"));
        }
    }

}
